import { ecsclass, EcsComponent } from '../../../../../../../../pkg-export/@gamex/cc-ecs';
import { playerBulletType } from '../../../Common';
import { MyEntity } from '../entity/MyEntity';

@ecsclass('PlayerComponent')
export class PlayerComponent extends EcsComponent<MyEntity> {
    static allowRecycling = true;
    protected onRemove() {
        this._attack = 1;
        this._attackSpeed = 10;
    }

    /**最大血量 */
    private _maxHp = 10;
    public get maxHp() {
        return this._maxHp;
    }
    public set maxHp(value) {
        if (value < 0) {
            value = 0
        }
        this._maxHp = value;
        if (this._hp > this._maxHp) {
            this._hp = this._maxHp;
        }
    }

    /**血量 */
    private _hp = 100;
    public get hp() {
        return this._hp
    }
    public set hp(value) {
        if (value < 0) {
            value = 0
        }
        if (value > this.maxHp) {
            value = this.maxHp;
        }
        this._hp = value
    }

    /**攻击力 */
    private _attack = 1;
    public get attack() {
        return this._attack;
    }
    public set attack(value) {
        if (value > 20) value = 20;
        this._attack = value;
    }
    /**攻速 每秒攻击次数*/
    private _attackSpeed = 10;
    public get attackSpeed() {
        return this._attackSpeed;
    }
    public set attackSpeed(value) {
        if (value > 10) value = 10;
        this._attackSpeed = value;
    }
    /**攻击间隔 */
    get interval() {
        return 1 / this._attackSpeed;
    };
    /**子弹类型 */
    private _bulletType = playerBulletType.M;
    public get bulletType() {
        return this._bulletType;
    }
    public set bulletType(value) {
        this._bulletType = value;
    }

}